import requests

headers = {
    "Accept": "*/*",
    "Accept-Language": "zh-CN,zh;q=0.9",
    # "Authorization": "timestamp=1763210272;oauth2=17c52e67a36733478c22cf7d6cf5724e;signature=58c28819e14f1ffab39c9d6fbd20caa6;secret=17c52e67a36733478c22cf7d6cf5724e",
    "Connection": "keep-alive",
    "Content-Type": "application/json",
    "Referer": "https://servicewechat.com/wxa0545fcd02d93b5d/196/page-frame.html",
    "Sec-Fetch-Dest": "empty",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Site": "cross-site",
    "Terminal": "windows",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090a13) UnifiedPCWindowsWechat(0xf2541211) XWEB/16815",
    "xweb_xhr": "1"
}
url = "https://66miniapp-api.66zhizu.com/client/search/house"
params = {
    "sequence": "",
    "city": "上海",
    "region": "",
    "distance": "",
    "longitude": "",
    "latitude": "",
    "stations": "",
    "bed_count": "",
    "rent_type": "",
    "sort": "",
    "cost1": "",
    "cost2": ""
}

import subprocess
from functools import partial

subprocess.Popen = partial(subprocess.Popen, encoding="utf-8")
import execjs

with open('01.js', "r", encoding="utf-8") as f:
    js_code = f.read()
# 编译 JS 代码
ctx = execjs.compile(js_code)
param = ctx.call("getAuthorization")
for i in range(1, 10):
    headers['Authorization'] = param
    response = requests.get(url, headers=headers, params=params)
    params['sequence'] = response.json()['result']['sequence']
    print(response.text)
    print(response)
